// ######################################################################//
// //
// Copyright [2011-2012] Delta Air Lines, Inc./Delta Technology, Inc. //
// All Rights Reserved //
// Access, Modification, or Use Prohibited //
// Without Express Permission of Delta Air Lines or Delta Technology. //
// //
// ######################################################################//

package com.delta.rafg.core.utils;

import org.apache.commons.lang.StringUtils;
/**
 * 
 * RAFGCoreUtils. This class is used for Core Utility
 * @author Delta
 * @version 1.0
 * @see LoginHandler
 */
public class RAFGCoreUtils {

    /**
     * 
     * This is a constructor of RAFGCoreUtils.java
     */
	private RAFGCoreUtils() {
		
	}
	/**
	 * This method returns the true if the given string is null or blank or white space else returns false.
	 * @param pValue
	 * @return Boolean
	 */
	public static Boolean isNullOrBlankOrWhiteSpace(String pValue){
		if((pValue!=null) &&(!StringUtils.isWhitespace(pValue))&& StringUtils.isNotBlank(pValue)  && (StringUtils.isNotEmpty(pValue))){
			return Boolean.FALSE;
		}else{
			return Boolean.TRUE;
		}
	}
	
	/**
	 * Determine if the passed in String is a number.
	 */
	public static boolean isANumber(final String aString) {
		try {
			Integer.parseInt(aString);
		}catch(NumberFormatException nfe) {
			return false;
		}
		
		return true;
	}
	
	/**
	 * This method is to remove all leading zero in given string
	 * if p_bStripAll = true means it will return blank if given string having all zeros
	 * if p_bStripAll = false means it will return zero if given string having all zeros 
	 * @param p_str
	 * @param p_bStripAll
	 * @return
	 */
	public static String removeLeadingZeroes(String p_str, boolean p_bStripAll) {
		String strStripped = "";
		if (p_str != null) {
			strStripped = p_str;
			int iRemainingDigits = p_bStripAll ? 0 : 1;
			char[] achar = p_str.toCharArray();
			if (achar != null && achar.length > iRemainingDigits) {
				int iLastChar = achar.length - iRemainingDigits;
				int i = 0;
				while (i < iLastChar && achar[i] == '0')
					i++;
				strStripped = String.valueOf(achar, i, achar.length - i);
			}
		}
		return strStripped;
	}

}
